/**
 * Java Operators Examples
 * This class demonstrates the usage of various operators in Java
 */
public class Operators {
    
    public static void main(String[] args) {
        Operators example = new Operators();
        
        example.demonstrateArithmeticOperators();
        example.demonstrateAssignmentOperators();
        example.demonstrateComparisonOperators();
        example.demonstrateLogicalOperators();
        example.demonstrateBitwiseOperators();
        example.demonstrateTernaryOperator();
        example.demonstrateOperatorPrecedence();
    }
    
    /**
     * Method to demonstrate arithmetic operators
     */
    public void demonstrateArithmeticOperators() {
        System.out.println("=== Arithmetic Operators ===");
        int a = 20;
        int b = 10;
        
        System.out.println("a = " + a + ", b = " + b);
        System.out.println("a + b = " + (a + b));  // Addition
        System.out.println("a - b = " + (a - b));  // Subtraction
        System.out.println("a * b = " + (a * b));  // Multiplication
        System.out.println("a / b = " + (a / b));  // Division
        System.out.println("a % b = " + (a % b));  // Modulus
        
        // Increment and decrement operators
        int c = 5;
        System.out.println("\nIncrement/Decrement Operators:");
        System.out.println("c = " + c);
        System.out.println("++c = " + (++c));  // Pre-increment
        System.out.println("c++ = " + (c++));  // Post-increment
        System.out.println("c = " + c);
        System.out.println("--c = " + (--c));  // Pre-decrement
        System.out.println("c-- = " + (c--));  // Post-decrement
        System.out.println("c = " + c);
    }
    
    /**
     * Method to demonstrate assignment operators
     */
    public void demonstrateAssignmentOperators() {
        System.out.println("\n=== Assignment Operators ===");
        int a = 10;
        System.out.println("a = " + a);
        
        a += 5;  // Equivalent to a = a + 5
        System.out.println("a += 5 -> a = " + a);
        
        a -= 3;  // Equivalent to a = a - 3
        System.out.println("a -= 3 -> a = " + a);
        
        a *= 2;  // Equivalent to a = a * 2
        System.out.println("a *= 2 -> a = " + a);
        
        a /= 4;  // Equivalent to a = a / 4
        System.out.println("a /= 4 -> a = " + a);
        
        a %= 3;  // Equivalent to a = a % 3
        System.out.println("a %= 3 -> a = " + a);
    }
    
    /**
     * Method to demonstrate comparison operators
     */
    public void demonstrateComparisonOperators() {
        System.out.println("\n=== Comparison Operators ===");
        int a = 10;
        int b = 20;
        
        System.out.println("a = " + a + ", b = " + b);
        System.out.println("a == b: " + (a == b));
        System.out.println("a != b: " + (a != b));
        System.out.println("a > b: " + (a > b));
        System.out.println("a < b: " + (a < b));
        System.out.println("a >= b: " + (a >= b));
        System.out.println("a <= b: " + (a <= b));
    }
    
    /**
     * Method to demonstrate logical operators
     */
    public void demonstrateLogicalOperators() {
        System.out.println("\n=== Logical Operators ===");
        boolean x = true;
        boolean y = false;
        
        System.out.println("x = " + x + ", y = " + y);
        System.out.println("x && y: " + (x && y));  // Logical AND
        System.out.println("x || y: " + (x || y));  // Logical OR
        System.out.println("!x: " + (!x));          // Logical NOT
        System.out.println("!y: " + (!y));
    }
    
    /**
     * Method to demonstrate bitwise operators
     */
    public void demonstrateBitwiseOperators() {
        System.out.println("\n=== Bitwise Operators ===");
        int a = 5;   // Binary: 0101
        int b = 3;   // Binary: 0011
        
        System.out.println("a = " + a + " (binary: 0101)");
        System.out.println("b = " + b + " (binary: 0011)");
        System.out.println("a & b = " + (a & b) + " (binary: 0001)");   // Bitwise AND
        System.out.println("a | b = " + (a | b) + " (binary: 0111)");   // Bitwise OR
        System.out.println("a ^ b = " + (a ^ b) + " (binary: 0110)");   // Bitwise XOR
        System.out.println("~a = " + (~a) + " (binary: 1010)");         // Bitwise NOT
        System.out.println("a << 1 = " + (a << 1) + " (binary: 1010)"); // Left shift
        System.out.println("a >> 1 = " + (a >> 1) + " (binary: 0010)"); // Right shift
    }
    
    /**
     * Method to demonstrate ternary operator
     */
    public void demonstrateTernaryOperator() {
        System.out.println("\n=== Ternary Operator ===");
        int a = 10;
        int b = 20;
        
        // Using ternary operator to find maximum of two numbers
        int max = (a > b) ? a : b;
        System.out.println("Maximum of " + a + " and " + b + " is: " + max);
        
        // Another example with string
        String result = (a % 2 == 0) ? "even" : "odd";
        System.out.println(a + " is " + result);
    }
    
    /**
     * Method to demonstrate operator precedence
     */
    public void demonstrateOperatorPrecedence() {
        System.out.println("\n=== Operator Precedence ===");
        int a = 10;
        int b = 5;
        int c = 2;
        
        // Multiplication has higher precedence than addition
        int result1 = a + b * c;  // 10 + (5 * 2) = 20
        System.out.println("a + b * c = " + a + " + " + b + " * " + c + " = " + result1);
        
        // Using parentheses to change precedence
        int result2 = (a + b) * c;  // (10 + 5) * 2 = 30
        System.out.println("(a + b) * c = (" + a + " + " + b + ") * " + c + " = " + result2);
        
        // Complex expression
        boolean result3 = a > b && b < c || c == 2;
        System.out.println("a > b && b < c || c == 2: " + result3);
    }
}